//导入axios
import axios from "axios";

//进行一些全局配置
//公共路由(网络请求地址)
axios.defaults.baseURL = 'http://119.23.73.128:80/'
//axios.defaults.baseURL = 'http://localhost:80/'
axios.defaults.timeout = 5000;

//封装get/post方法
export default {
    get: function(path = '', data = {}, header = {}) {
        return new Promise(function(resolve, reject) {
            axios({
                method: 'get',
                url: path,
                params: data,
                headers: header
            }).then(
                response => {
                    resolve(response.data)
                },
                error => {
                    reject(error);
                })
        })
    },
    post: function(path = '', data = {}, header = {}) {
        return new Promise(function(resolve, reject) {
            axios({
                    method: 'post',
                    url: path,
                    data: data,
                    headers: header
                })
                .then(
                    response => {
                        resolve(response.data)
                    },
                    error => {
                        reject(error);
                    }
                )
        })
    },
    put: function(path = '', data = {}, header = {}) {
        return new Promise(function(resolve, reject) {
            axios({
                    method: 'put',
                    url: path,
                    data: data,
                    headers: header
                })
                .then(
                    response => {
                        resolve(response.data)
                    },
                    error => {
                        reject(error);
                    }
                )
        })
    }
}